package jf.states.graph;

import java.util.HashMap;
import java.util.Map;

import jf.closure.F2;
import jf.collections.Tuple3;

/**
 * @author ivanalx
 * @date 06.05.2009 17:31:12
 */
public class DynamicExpirationDescription<S, A, T> implements ExpirationDescription<S,A,T> {
	private final Map<S, A> actionForExpireObject;
	private final Map<S, F2<S, T, Long>> experationTimeForObject;

	public DynamicExpirationDescription(Tuple3<S, A, F2<S, T, Long>>... config) {
		actionForExpireObject = new HashMap<S,A>();
		experationTimeForObject = new HashMap<S, F2<S,T, Long>>();
		for (Tuple3<S, A, F2<S, T, Long>> d : config) {
			actionForExpireObject.put(d._1, d._2);
			experationTimeForObject.put(d._1, d._3);
		}
	}

	public A getActionForExpiredObject(S state) {
		return actionForExpireObject.get(state);
	}

	public Long getTimeForExpireForObject(S state, T o) {
		F2<S, T, Long> f = experationTimeForObject.get(state);
		return f != null? f.apply(state, o): null;
	}
}
